<template>
  <div>
    <city-header></city-header>
    <city-search :cities="cities"></city-search>
    <city-list :hot="hotCities"
               :cities="cities"
               :letter="letter"></city-list>
    <city-alphabet :cities="cities"
                   @cityChange="cityChange"></city-alphabet>
  </div>
</template>

<script>
import axios from 'axios'
import CityHeader from './components/cityHeader'
import CitySearch from './components/citySearch'
import CityList from './components/cityList'
import CityAlphabet from './components/alphabet'

export default {
  name: 'City',
  components: {
    CityHeader,
    CitySearch,
    CityList,
    CityAlphabet
  },
  data () {
    return {
      cities: {},
      hotCities: [],
      letter: ''
    }
  },
  mounted () {
    this.getCityInfo()
  },
  methods: {
    getCityInfo () {
      axios.get('/api/city.json')
        .then(this.cityInfoGetSuss)
    },
    cityInfoGetSuss (res) {
      var result = res.data
      if (result.ret && result.data) {
        const data = result.data
        this.hotCities = data.hotCities
        this.cities = data.cities
      }
    },
    cityChange (letter) {
      this.letter = letter
    }
  }
}
</script>

<style >
</style>
